package com.ys.p5TreeMap了解;

import java.util.Objects;

/**
 * 描述:
 *
 * @author CodeYang
 * @version 2020/12/28 19:37
 */
public class Student implements Comparable<Student>{
    private String name;
    private Integer age;

    public Student() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Student(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    /**
     * 内部比较器 一般只做一种规则的比较
     *  如: 做 年龄的升序排序
     *  升序的比较器
     *  当前.age - 形参.age
     *           >         正数
     *           <         负数
     *           =          0
     *  小的放前面,大的放后面.
     *  降序:
     *  大在前,小在后
     * @param o
     * @return
     */
    @Override
    public int compareTo(Student o) {
       // return this.age - o.age;
        // 加一个- 号就可以改升序为降序
        return (this.age - o.age);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return Objects.equals(name, student.name) &&
                Objects.equals(age, student.age);
    }

//    @Override
//    public int hashCode() {
//        return Objects.hash(name, age);
//    }
}
